package com.alibaba.travel.scenic.controller;

import com.alibaba.travel.scenic.entity.ScenicSpotEntity;
import com.alibaba.travel.scenic.entity.UserScenicHistoryEntity;
import com.alibaba.travel.scenic.service.UserScenicHistoryService;
import com.alibaba.travel.common.utils.PageUtils;
import com.alibaba.travel.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 用户旅游景点历史表
 *
 * @author wherezy
 * @email wherezy@tom.com
 * @date 2023-02-23 15:10:18
 */
@Api(tags = {"用户旅游景点历史表UserScenicHistoryController"})
@RestController
@RequestMapping("scenic/userscenichistory")
public class UserScenicHistoryController {
    @Autowired
    private UserScenicHistoryService userScenicHistoryService;

    /**
     * 列表
     */
    @ApiOperation(value="分页获取信息", notes="k-v map形式封装分页参数")
    @PostMapping("/list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = userScenicHistoryService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation(value="获取信息")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		UserScenicHistoryEntity userScenicHistory = userScenicHistoryService.getById(id);

        return R.ok().put("userScenicHistory", userScenicHistory);
    }

    /**
     * 保存
     */
    @ApiOperation(value="保存")
    @PostMapping("/save")
    public R save(@RequestBody UserScenicHistoryEntity userScenicHistory){
		userScenicHistoryService.save(userScenicHistory);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value="修改")
    @PostMapping("/update")
    public R update(@RequestBody UserScenicHistoryEntity userScenicHistory){
		userScenicHistoryService.updateById(userScenicHistory);

        return R.ok();
    }


    /**
     * 查看历史旅游景点   select * from tb where id = user_id
     *
     */
    @ApiOperation(value="查看历史旅游景点")
    @GetMapping("/selectPageHistorical/{userId}")
    public R selectPageHistorical(@PathVariable("userId") Long id,@RequestParam("page") Integer page,
                                  @RequestParam("pageSize") Integer pageSize){
        //查看某个用户的历史旅游景点
        return userScenicHistoryService.pageSelect(id,page,pageSize);

    }

    /**
     * 删除
     */
    @ApiOperation(value="删除")
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		userScenicHistoryService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
